﻿using System.Web.Mvc;
using YuYuKiCms.Bl.Attribute;
using YuYuKiCms.Bl.Interface;
using YuYuKiCms.Framework.Interface;
using YuYuKiCms.Internet.Properties;

namespace YuYuKiCms.Internet.Controllers
{
    [DynamicLayout]
    public class HomeController : Controller
    {
        private readonly IHomeBL _homeBL;
        private readonly IThemeBL _themeBL;
        private readonly IUtil _util;

        public HomeController(IHomeBL homeBL, IUtil util, IThemeBL themeBL)
        {
            _homeBL = homeBL;
            _util = util;
            _themeBL = themeBL;
        }

        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }

        public void Redirect()
        {
            var lg = _homeBL.GetLanguage(Request, Settings.Default.LANGUAGE);

            _util.SetCookie(Response, lg);

            //Response.RedirectToRoute("LocalizeRoute", new {language = lg, url = ""});
            Response.Redirect("~/fr/Home/ContentHtml");

            //return RedirectToAction("ContentHtml", new { language = lg });
        }

        /// <summary>
        ///     Retrieve html content depend on <paramref name="url" /> and selected theme
        /// </summary>
        /// <param name="url">url written in the browser</param>
        public ActionResult ContentHtml(string url)
        {
            ViewBag.Body = string.Format("<h1>{0}</h1>", url);

            return View();
        }
    }
}